<template>
	
	<div>
		
		
		<div class="border_bottom"  v-for="(item,index) in list" @click="toDetail(index)">

	         <flexbox >
	
	            <flexbox-item :span="1/10">
	            	<div class="cell" v-if="item.is_read == 0">
	            	  <img src="../../static/image/dian.png" style="margin-top: 0.5rem;"/>
	                </div>
	                <div class="cell" v-if="item.is_read == 1">
	            	  
	                </div>
	            </flexbox-item> 
	            <flexbox-item :span="8/10">
	            	<div class="byjl">
	            	  <div style="line-height: 1.8rem;">{{item.message_name}}</div>
	            	  <div style="font-size: 0.1rem;color: #949293;">{{item.message_addtime}}</div>
	                </div>
	            </flexbox-item>  
	            <flexbox-item :span="1/10"><div class="xf iconfont icon-right"></div></flexbox-item> 
	
	        </flexbox>
	
	    </div>
		
		<tab></tab>
		
	</div>
	
	
</template>

<script>
	
	import { base64} from 'vux'
	
	export default {
		
		components: {
		    base64
		},
		
		data () {
	    	return {
		      
		      list:'',
		      message_id:'',
		      id:'',
		      access_token:''
		      
		    }

	    },
		
		methods: {
			
			//获取详情
		    getDetail(){
		    	
		    	this.$store.commit('updateLoadingStatus',true);
		    	
		    	this.$http.get(this.$store.state.api + 'message/msg&access_token=' + this.access_token)
		    	.then((response) => {
		    		
		    		console.log(response)
		    		
				
				if(response.body.code == 0) {
					
					this.list = response.body.data.list;
					
					this.$store.state.bage = response.body.data.count;
					
				} else {
					
				}
				
				this.$store.commit('updateLoadingStatus',false);
				
				
			    }, (response) => {
	             
	             
			    });
		    },
			
			
			//跳转到详情页面
			toDetail(index){
				
				
				console.log(index)
				
				this.message_id = this.list[index].message_id
				this.id = this.list[index].id
				
				this.$router.push({ path: '/newsSpecific',name:'newsSpecific',params:{message_id:this.message_id}});
				
				
				
				this.$store.commit('updateLoadingStatus',true);
			    	
		    	this.$http.get(this.$store.state.api + 'message/read&access_token=' + this.access_token + '&id=' + this.id)
		    	.then((response) => {
		    		
		    		console.log(response)
		    		
				
				if(response.body.code == 0) {
					
					
				} else {
					
				}
				
				this.$store.commit('updateLoadingStatus',false);
				
				
			    }, (response) => {
	             
	             
			    });
				
				
			},
			
			//获取地址栏信息
			getUrlStr(name){
		      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
		      if(reg.test(window.location.href)){
		        return unescape(RegExp.$2.replace(/\+/g," "))
		      }
		      return undefined
		    },
			
				
			},
		
		mounted() {
			
			var access_token = this.getUrlStr('access_token');
           var parentId = this.getUrlStr('parent_id');
           
            if(parentId == undefined){
              parentId = 0;
           }
           
           var uid = this.getUrlStr('uid');
           
           if(parentId.toString().indexOf('?') > 0){
           	 parentId = parentId.split('?')[0];
           }
           
           var locurl = location.href;
           locurl = base64.encode(locurl.split('?')[0]);
           
       
           if(access_token != undefined){
         
              localStorage.setItem("access_token",access_token); 
              localStorage.setItem("parent_id",this.getUrlStr('uid'));


           }
           
            if(localStorage.getItem('access_token') != null){
         
              this.$root.registerjudge();
              this.$root.getShare();
              
            }else{
            	
        	  this.$root.gotoWechat(locurl,parentId);
            }
           
    	   this.access_token = localStorage.getItem('access_token');
			
            this.getDetail();
            
            

        }
		
		
		
		
		
	}
	
	
</script>

<style>
	
	.border_bottom{
	   border-bottom:1px #9D9E9E solid;box-sizing: border-box;
	}
	.cell{
	   color: #7b7b7b; font-size: 15px;height: 44px;line-height: 44px;font-size: 25px; margin-left: 10px;
	}
	
</style>